require 'crawler/crawler'
require 'uri'
require 'date'

module Crawler
  
  class LastfmCrawler < Crawler
    
    public
    
    def initialize(args = {})
      super(args)
    end
    
    def service_name
      'lastfm'
    end
    
    def crawl_table
      LastfmCrawl  
    end
    
    protected 
    
    def crawl(c)
      request_uri = "http://ws.audioscrobbler.com/2.0/?method=user.getinfo&user=#{URI.escape(c.service.username_on_service)}&api_key=b25b959554ed76058ac220b7b2e0a026"
      @curl.url = request_uri
      response = false
      
      begin
        @curl.http_get    
        c.status = @curl.response_code
        response = @curl.response_code == 200
        c.body = @curl.body_str
      end
      response
    end
    
    def has_crawl?(s)
      !s.lastfm_crawl.nil?
    end
    
  end 
  
end